import 'package:appflutter/MyModules/Dashline_widget.dart';
import 'package:appflutter/MyModules/StarsWidget.dart';
import 'package:appflutter/Pages/Home/home_model.dart';
import 'package:flutter/material.dart';

class home_movie_item extends StatelessWidget {
  final movie_item movie;

  home_movie_item(this.movie);

  @override
  Widget build(BuildContext context) {

    return Container(
      padding: EdgeInsets.all(10),
      decoration: BoxDecoration(
        border: Border(bottom:BorderSide(width: 10,color: Color(0xffe2e2e2)))
      ),
      child: Column(

        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          top_rank(),
          SizedBox(height: 12,),
          movie_content(),
          SizedBox(height: 12,),
          bottom_des(),
        ],
      ),
    );
  }

  //顶部
  Widget top_rank() {

    return Container(
        padding: EdgeInsets.fromLTRB(9, 4, 9, 4),
        decoration: BoxDecoration(
            color: Color.fromARGB(255, 238, 205, 144),
            borderRadius: BorderRadius.circular(3)),
        child: Text(
          'No. ${movie.rank + 1}',
          style:
              TextStyle(fontSize: 18, color: Color.fromARGB(255, 131, 95, 36)),
        ));
  }

  //中间内容
  Widget movie_content(){

    return Container(
      height: 150,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          getImage(),
          content(),
          dash_line(),
          wish_look(),

        ],

      ),
    );

  }
  //01.image
  Widget getImage(){
    return ClipRRect(
        borderRadius: BorderRadius.circular(3),
        child: Image.network('${movie.imageUrl}')
    );
  }
  //02.内容
  Widget content (){

    return Expanded(//会撑开
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            content_title(),
            SizedBox(height: 6,),
            rating(),
            SizedBox(height: 6,),
            des()

          ],
        ),

      ),
    );

  }

  //标题
  Widget content_title (){

    return Container(

      child: Stack(
        children: <Widget>[
          Icon(Icons.play_circle_outline,color: Colors.redAccent,),
          Text.rich(
            TextSpan(
              children: [
                TextSpan(
                  text: '        ${movie.title}',
                  style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold),
                ),
                TextSpan(
                  text: '  (${movie.playDate})',
                  style: TextStyle(color: Colors.grey[600])

                )
              ]

            ),
            maxLines: 2,
          )
          
        ],
        
      ),
      
    );

  }
  //星星
  Widget rating(){
    return Row(
      children: <Widget>[
        StarsWidget(currentStars: movie.rating,StarSize: 18,selectedStarColor: Colors.yellow,),
        SizedBox(width: 8,),
        Text('${movie.rating}',style: TextStyle(color: Colors.grey[700]),)

      ],
    );
  }
  //介绍
  Widget des(){
    var castString = '';
    for (final cast in movie.casts){
      castString += cast.name;
    }
    return Text(
      '${movie.genres.join(' ')} /${movie.director.name} / $castString',
      style: TextStyle(fontSize: 13,),
      maxLines: 2,
        overflow: TextOverflow.clip,
    );
  }


  //03 .虚线
  Widget dash_line(){
    return Dash_lineWidget(
      axis: Axis.vertical,
      dashHeight: 3,
      color: Colors.grey[600],
      count: 18,
    );
  }

  //04. 想看
  Widget wish_look(){
    return Container(
      width: 55,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Image.asset('assets/home/wish.png',width: 36,),
          Text(' 想看',style: TextStyle(color: Color.fromARGB(255, 131, 95, 36)),)
        ],
      ),

    );
  }

  //05. 底部
  Widget bottom_des(){

    return Container(

      padding: EdgeInsets.fromLTRB(9, 8, 9, 8),
      width: double.infinity,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(3),
        color: Colors.grey[200],
      ),
      child: Text(
          '${movie.originalTitle}',
        style: TextStyle(fontSize: 16),
      ),
      
    );
  }
}
